/*
 * EquipmentBasicShield.cpp
 *
 *  Created on: Jun 16, 2012
 *      Author: gonzalo
 */

#include "EquipmentBasicShield.h"
#include "../PlayScenarioPanel.h"

#define BASIC_SHIELD_IMAGE "./resources/img/objetos/basicShield.png"

#define CIEN 100

#define FIX_ENERGYBAR_BASICSHIELD PROGRESS_BARRA_HEIGHT / 2

EquipmentBasicShield::EquipmentBasicShield(Widget* parent) : Equipment(BASIC_SHIELD,parent) {
	this->surface = SurfaceUtils::loadImage(BASIC_SHIELD_IMAGE);
	this->energy = new ProgressBar(CIEN,0,0,this->parent);
}

EquipmentBasicShield::EquipmentBasicShield(DTOEquipment* dtoEquipment,Widget* parent):
Equipment(dtoEquipment->bonusType, parent){
	this->surface = SurfaceUtils::loadImage(BASIC_SHIELD_IMAGE);
	this->energy = new ProgressBar(dtoEquipment->value,0,0,this->parent);
}

void EquipmentBasicShield::handleEvent(Event event){
	//Nada, el shield no maneja eventos, previene de los ammo
}
void EquipmentBasicShield::updateStatus(){
	energy->resetBar(CIEN);
}

int EquipmentBasicShield::reduceLife(int value,playElement element){
	return (element == AMMO) ? energy->reducePercent(value) : value;
}

void EquipmentBasicShield::updatePosition(int offsetX,int offsetY) {

	rect = this->surface->clip_rect;
	rect.x = offsetX - rect.w / 2;
	rect.y = offsetY - rect.h / 2;

	//Calculo la posicion relativa del progress bar
	energy->parcel->updateXY(offsetX - SH_DEFAULT_WIDHT / 2,rect.y + rect.h + energy->parcel->getRectangle().w / 2 );
}

void EquipmentBasicShield::showOn(SDL_Surface* surface,int offsetX,int offsetY) {
	emptyFlag = (energy->getPorcent() <= 0);

	updatePosition(offsetX,offsetY);

	SDL_BlitSurface(this->surface, NULL, surface, &rect);

	energy->showOn(surface);
}

DTOEquipment* EquipmentBasicShield::getDTO() {
	return new DTOEquipment(BASIC_SHIELD,this->energy->getPorcent(),((PlayScenarioPanel*)parent)->getOwner());
}

EquipmentBasicShield::~EquipmentBasicShield() {}

